import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

class QueueSecond extends StatefulWidget {
  Map arguments;
  QueueSecond({Key key, this.arguments}) : super(key: key);

  @override
  _QueueSecondState createState() =>
      _QueueSecondState(arguments: this.arguments);
}

class _QueueSecondState extends State<QueueSecond> {
  Map arguments;
  _QueueSecondState({this.arguments});

  _cancleQueue() async {
    print(arguments);
    var apiUrl = 'http://192.168.0.103:5758/app/queue/cancelQueue'; // 需要更换成本地ip
    Map jsonData = {"vno": arguments['vno'], "id": arguments['id']};
    Response response = await Dio().post(apiUrl, data: jsonData);
    print(response);
    if (response.data['status'] == 0) {
      Navigator.pushNamed(context, '/first');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('排队管理'),
        ),
        body: Container(
          // height: 150,
          child: Column(children: [
            Card(
                child: Padding(
              padding: EdgeInsets.fromLTRB(15, 10, 15, 5),
              child: Column(
                children: [
                  Container(
                      padding: EdgeInsets.fromLTRB(30, 4, 30, 4),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(3.0),
                        color: Color.fromRGBO(128, 212, 248, 1),
                      ),
                      child: Text('!  进入厂区需提前排队取号，请先排队',
                          style: TextStyle(
                            // height: 1.5 / 1,
                            fontSize: 16,
                            color: Colors.white,
                          ))),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Expanded(
                          flex: 2,
                          child: Container(
                            child: Text('装：${arguments['loadGoodsAddr']}',
                                style: TextStyle(letterSpacing: 1)),
                          )),
                      SizedBox(width: 10),
                      Expanded(
                          flex: 1,
                          child: Container(
                            child: ElevatedButton(
                              child: Text('导航前往'),
                              onPressed: () {},
                            ),
                          )),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Expanded(
                          flex: 2,
                          child: Container(
                            child: Text('卸：${arguments['unloadGoodsAddr']}',
                                style: TextStyle(letterSpacing: 1)),
                          )),
                      SizedBox(width: 10),
                      Expanded(
                          flex: 1,
                          child: Container(
                            child: ElevatedButton(
                              child: Text('导航前往'),
                              onPressed: () {},
                            ),
                          )),
                    ],
                  )
                ],
              ),
            )),
            Padding(
                padding: EdgeInsets.fromLTRB(15, 10, 15, 5),
                child: Column(
                  children: [
                    Container(
                        alignment: Alignment.topLeft,
                        child: Text(
                          '车牌号：${arguments['vno']}',
                        )),
                    Container(
                        alignment: Alignment.topLeft,
                        child: Text(
                          '排队状态：${arguments['queueStatus'] == 1 ? '排队中' : ''}',
                        )),
                    Center(
                      child: Container(
                        height: 50,
                        child: Text('排队号码：${arguments["allocateNum"]}'),
                      ),
                    ),
                    Center(
                      child: Container(
                        height: 50,
                        child: Text('前面等待：${arguments['waitingNumber']}'),
                      ),
                    ),
                    Center(
                      child: Container(
                        height: 200,
                        child: Image.asset('images/qrcode.png'),
                      ),
                    ),
                    Center(
                      child: ElevatedButton(
                        child: Text('取消排队'),
                        onPressed: _cancleQueue,
                      ),
                    ),
                  ],
                ))
          ]),
        ));
  }
}
